package com.cloud.util.poi

import org.apache.poi.poifs.crypt.Decryptor
import org.apache.poi.poifs.crypt.EncryptionInfo
import org.apache.poi.poifs.filesystem.POIFSFileSystem
import org.apache.poi.xssf.usermodel.XSSFWorkbook
import java.io.File

class Test {

}

fun main(args: Array<String>) {
    val file = POIFSFileSystem(File("/Users/imac/Documents/workspace/副本凤凰日记2013.11.12.xlsx"))
    val encInfo = EncryptionInfo(file)
    val decryptor = Decryptor.getInstance(encInfo)
    var i = -1
    while (true) {
        val password = String.format("%06d", ++i)
        if (decryptor.verifyPassword(password)) {
            println(password)
            val book = XSSFWorkbook(decryptor.getDataStream(file))
            val sheet = book.getSheetAt(0)
            sheet.rowIterator().forEach {
                it.cellIterator().forEach {
                    println(it.stringCellValue)
                }
            }
        }
        break
    }

}